package com.tian.controller.market.api;

import com.tian.common.annotation.LoginCheckAnnotation;
import com.tian.common.util.CommonResult;
import com.tian.common.util.PageResult;
import com.tian.dto.market.coupon.QueryCouponIdCouponAmountReqDto;
import com.tian.dto.market.user.UserCouponAddReqDto;
import com.tian.dto.market.user.UserCouponPageReqDto;
import com.tian.dto.market.user.UserCouponPageRespDto;
import com.tian.dto.market.user.UserCouponRespDto;
import com.tian.service.market.ChargeUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * {@code @description:} 用户的优惠券
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024/1/23 9:33
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/market/api/user/coupon")
@Api(tags = "我的礼券 控制器")
public class UserCouponApiController {
    @Resource
    private ChargeUserCouponService chargeUserCouponService;


    @ApiOperation(value = "领取优惠券", notes = "领取优惠券")
    @ApiResponses({@ApiResponse(code = 200000, message = "操作成功")})
    @LoginCheckAnnotation
    @PostMapping("/add")
    public CommonResult<Boolean> add(@RequestBody UserCouponAddReqDto userCouponAddReqDto) {
        return chargeUserCouponService.add(userCouponAddReqDto);
    }

    @ApiOperation(value = "分页查询我的优惠券", notes = "分页数据")
    @ApiResponses({@ApiResponse(code = 200000, message = "操作成功")})
    @PostMapping("/page")
    @LoginCheckAnnotation
    public CommonResult<PageResult<List<UserCouponPageRespDto>>> page(@RequestBody UserCouponPageReqDto userCouponPageReqDto) {
        return chargeUserCouponService.page(userCouponPageReqDto);
    }

    @ApiOperation(value = "优惠券详情", notes = "优惠券详情数据")
    @ApiResponses({@ApiResponse(code = 200000, message = "操作成功")})
    @GetMapping("/{id}")
    @LoginCheckAnnotation
    public CommonResult<UserCouponRespDto> findById(@PathVariable("id") Long id) {
        return chargeUserCouponService.findById(id);
    }

    @ApiOperation(value = "我的优惠券数量", notes = "我的优惠券数量")
    @ApiResponses({@ApiResponse(code = 200000, message = "操作成功")})
    @LoginCheckAnnotation
    @GetMapping("/count")
    public CommonResult<Long> count() {
        return chargeUserCouponService.count();
    }

    @ApiOperation(value = "计算优惠金额")
    @ApiResponses({@ApiResponse(code = 200000, message = "操作成功")})
    @PostMapping("/ids/coupon/amount")
    @LoginCheckAnnotation
    public CommonResult<String> queryCouponIdCouponAmount(@RequestBody QueryCouponIdCouponAmountReqDto queryCouponIdCouponAmountReqDto) {
        return chargeUserCouponService.queryCouponIdCouponAmount(queryCouponIdCouponAmountReqDto);
    }
}
